<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<script type="text/javascript">

jQuery(document).ready(function() {
    DomainProcessor.init();
});

if (typeof (DomainProcessor) == 'undefined') {
    var DomainProcessor = {
        columns : [],
        processInsertResponse : function(response, postdata) {
            var success = true;
            var msg = "";
            if(response.responseText != "") {
                var obj = jQuery.parseJSON(response.responseText);
                if(obj != null && obj.error !== undefined) {
                    success = false;
                    
                    msg = "<ul>";
                    $.each(obj.error, function(index, value) {
                        msg += "<li>" + value + "</li>";
                    });
                    msg += "</ul>";
                }
            }
            return [success, msg, null];
        },
        processUpdateResponse : function(response) {
            var success = true;
            var msg = "";
            if(response.responseText != "") {
                var obj = jQuery.parseJSON(response.responseText);
                if(obj != null && obj.error !== undefined) {
                    success = false;
                    
                    msg = "";
                    $.each(obj.error, function(index, value) {
                        if (index > 0) {
                            msg += "\n";
                        }
                        msg += value;
                    });
                    alert(msg);
                }
            }
            return success;
        },
        init : function() {
            jQuery("#gridContainer").jqGrid({
                ajaxGridOptions : {
                    type : 'POST',
                    contentType : 'application/json'
                },
                ajaxRowOptions : {
                    type : 'POST',
                    contentType : 'application/json'
                },
                serializeRowData : function(postdata) {
                    return $.toJSON(postdata);
                },
                serializeGridData : function(postdata) {
                    if(postdata.search == true) {
                        if(DomainProcessor.columns.length == 0) {
                            var colModel = jQuery("#gridContainer").jqGrid('getGridParam','colModel');
                            $.each(colModel, function(i, item) {
                                DomainProcessor.columns.push(item.name);
                            });
                        }
                        
                        var transformedPostData = {};
                        var objectJson = new Object;
                        
                        $.each(postdata, function(i, item) {
                            if(-1 != jQuery.inArray(i, DomainProcessor.columns)) {
                                if(objectJson['criteria'] == undefined) {
                                    objectJson['criteria'] = {};
                                }
                                objectJson['criteria'][i] = item;
                            } else {
                                objectJson[i] = item;
                            }
                        });
                        
                        postdata = objectJson;
                    }
                    return $.toJSON(postdata);
                },
                url : 'management/index.action',
                editurl : 'management/update.action',
                jsonReader: {
                    root : 'gridData',
                    page : 'currPage',
                    total : 'totalPages',
                    records : 'totalRecords',
                    repeatitems : false
                },
                datatype : 'json',
                colNames : [ 
                            '#',
							'<spring:message code="Watch.location"/>',
							'<spring:message code="Watch.maker"/>',
							'<spring:message code="Watch.painter"/>',
							'<spring:message code="Watch.caseNo"/>',
							'<spring:message code="Watch.movementNo"/>',
							'<spring:message code="Watch.commentsFromKladde"/>',
							'<spring:message code="Watch.watchComments"/>',
							'<spring:message code="Watch.trActComments"/>',
                            '<spring:message code="Watch.toDo"/>',
							'<spring:message code="Watch.status"/>',
							'<spring:message code="Watch.noOfWatches"/>',
							'<spring:message code="Watch.infile"/>',
							'<spring:message code="Watch.withCaseSeprt"/>',
							'<spring:message code="Watch.op102701InSfrHiEst"/>',
							'<spring:message code="Watch.usedHigh"/>',
							'<spring:message code="Watch.rInventoryCheck10810"/>',
							'<spring:message code="Watch.dsSfr92110"/>',
							'<spring:message code="Watch.sfrOp7806"/>',
							'<spring:message code="Watch.sfrAurelBacsTimBourneChristies6803"/>',
							'<spring:message code="Watch.r82602Price"/>',
							'<spring:message code="Watch.opSfr52302"/>',
							'<spring:message code="Watch.opSfr7201"/>',
							'<spring:message code="Watch.opSfr7799"/>',
							'<spring:message code="Watch.opSft61198"/>',
							'<spring:message code="Watch.opUsd61198"/>',
							'<spring:message code="Watch.opSfr52598"/>',
							'<spring:message code="Watch.dsHiSfr51697"/>',
							'<spring:message code="Watch.sab8696YellowIs21897"/>',
							'<spring:message code="Watch.rzSfr8796YellowIs21997"/>',
							'<spring:message code="Watch.hcSfr52996"/>',
							'<spring:message code="Watch.opSfr496"/>',
							'<spring:message code="Watch.dsSfr396"/>',
							'<spring:message code="Watch.rzSfr396"/>',
							'<spring:message code="Watch.opSfr61495"/>',
							'<spring:message code="Watch.opSfr990"/>',
							'<spring:message code="Watch.locPw858897"/>',
							'<spring:message code="Watch.dsLowSfr51697"/>',
							'<spring:message code="Watch.dsLow"/>',
							'<spring:message code="Watch.dsHigh51697"/>',
							'<spring:message code="Watch.repairComments"/>',
							'<spring:message code="Watch.saxNo"/>',
							'<spring:message code="Watch.oneNoteLink"/>',
							'<spring:message code="Watch.year"/>',
							'<spring:message code="Watch.diameter"/>',
							'<spring:message code="Watch.dial"/>',
							'<spring:message code="Watch.material"/>',
							'<spring:message code="Watch.caseType"/>',
							'<spring:message code="Watch.winding"/>',
							'<spring:message code="Watch.escapement"/>',
							'<spring:message code="Watch.repeater"/>',
							'<spring:message code="Watch.spec1"/>',
							'<spring:message code="Watch.spec2"/>',
							'<spring:message code="Watch.spec3"/>',
							'<spring:message code="Watch.spec4"/>',
							'<spring:message code="Watch.spec5"/>',
							'<spring:message code="Watch.automaton"/>',
							'<spring:message code="Watch.buyDate"/>',
							'<spring:message code="Watch.sellerId"/>',
							'<spring:message code="Watch.brokerId"/>',
							'<spring:message code="Watch.buyPlace"/>',
							'<spring:message code="Watch.currency"/>',
							'<spring:message code="Watch.price"/>',
							'<spring:message code="Watch.commissions"/>',
							'<spring:message code="Watch.fees"/>',
							'<spring:message code="Watch.totalAmtPaid"/>',
							'<spring:message code="Watch.dmXchangeRate"/>',
							'<spring:message code="Watch.dmTotalAmount"/>',
							'<spring:message code="Watch.euroTotalAmt"/>',
							'<spring:message code="Watch.salesDate"/>',
							'<spring:message code="Watch.salesPrice"/>',
							'<spring:message code="Watch.salesCurrency"/>',
							'<spring:message code="Watch.dmXchangeRate2"/>',
							'<spring:message code="Watch.bookId"/>',
							'<spring:message code="Watch.pageRef1"/>',
							'<spring:message code="Watch.lotNo"/>',
							'<spring:message code="Watch.catalogBy"/>',
							'<spring:message code="Watch.catalogDate"/>',
							'<spring:message code="Watch.watchRef1"/>',
							'<spring:message code="Watch.watchRef2"/>',
							'<spring:message code="Watch.watchRef3"/>',
							'<spring:message code="Watch.updated"/>',
							'<spring:message code="Watch.pic"/>'
                             ],
                             colModel : [ 
									{
 										name: 'id',
 										index: 'id',
 										width : 10,
  			                            key : true,
							            title: false,
										search: false,
 										hidden: false
									},								
									{
										name: 'location',
										index: 'location',
										width:50,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    }
									},
									{
										name: 'maker',
										index: 'maker',
										width:50,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    }
									},								
									{
										name: 'painter',
										index: 'painter',
										width:50,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    }
									},
									{
										name: 'caseNo',
										index: 'caseNo',
										width:50,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    }
									},							
									{
										name: 'movementNo',
										index: 'movementNo',
										width:50,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    }
									},
									{
										name: 'commentsFromKladde',
										index: 'commentsFromKladde',
										width:50,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    }
									},
									{
										name: 'watchComments',
										index: 'watchComments',
										width:50,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    }
									},
									{
										name: 'trActComments',
										index: 'trActComments',
										width:50,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    }
									},
									
									
									
									{
										name: 'toDo',
										index: 'toDo',
										width:80,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'status',
										index: 'status',
										width:80,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										search: true,
					                    searchoptions : {
					                        dataEvents:[{type:'keyup', fn: doSearch}]
					                    },
										hidden: true
									},
									{
										name: 'noOfWatches',
										index: 'noOfWatches',
										width:80,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},									
									{
										name: 'infile',
										index: 'infile',
										width:80,
										align: 'left',
							            title: false,
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},									
									{
										name: 'withCaseSeprt',
										index: 'withCaseSeprt',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},								
									{
										name: 'op102701InSfrHiEst',
										index: 'op102701InSfrHiEst',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},									
									{
										name: 'usedHigh',
										index: 'usedHigh',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},									
									{
										name: 'rInventoryCheck10810',
										index: 'rInventoryCheck10810',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dsSfr92110',
										index: 'dsSfr92110',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'sfrOp7806',
										index: 'sfrOp7806',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'sfrAurelBacsTimBourneChristies6803',
										index: 'sfrAurelBacsTimBourneChristies6803',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'r82602Price',
										index: 'r82602Price',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opSfr52302',
										index: 'opSfr52302',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opSfr7201',
										index: 'opSfr7201',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opSfr7799',
										index: 'opSfr7799',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opSft61198',
										index: 'opSft61198',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opUsd61198',
										index: 'opUsd61198',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opSfr52598',
										index: 'opSfr52598',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dsHiSfr51697',
										index: 'dsHiSfr51697',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'sab8696YellowIs21897',
										index: 'sab8696YellowIs21897',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'rzSfr8796YellowIs21997',
										index: 'rzSfr8796YellowIs21997',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'hcSfr52996',
										index: 'hcSfr52996',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opSfr496',
										index: 'opSfr496',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dsSfr396',
										index: 'dsSfr396',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'rzSfr396',
										index: 'rzSfr396',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opSfr61495',
										index: 'opSfr61495',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'opSfr990',
										index: 'opSfr990',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'locPw858897',
										index: 'locPw858897',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dsLowSfr51697',
										index: 'dsLowSfr51697',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dsLow',
										index: 'dsLow',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dsHigh51697',
										index: 'dsHigh51697',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'repairComments',
										index: 'repairComments',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'saxNo',
										index: 'saxNo',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'oneNoteLink',
										index: 'oneNoteLink',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'year',
										index: 'year',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'diameter',
										index: 'diameter',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dial',
										index: 'dial',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'material',
										index: 'material',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'caseType',
										index: 'caseType',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'winding',
										index: 'winding',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'escapement',
										index: 'escapement',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'repeater',
										index: 'repeater',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'spec1',
										index: 'spec1',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'spec2',
										index: 'spec2',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'spec3',
										index: 'spec3',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'spec4',
										index: 'spec4',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'spec5',
										index: 'spec5',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'automaton',
										index: 'automaton',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'buyDate',
										index: 'buyDate',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'sellerId',
										index: 'sellerId',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'brokerId',
										index: 'brokerId',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'buyPlace',
										index: 'buyPlace',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'currency',
										index: 'currency',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'price',
										index: 'price',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'commissions',
										index: 'commissions',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'fees',
										index: 'fees',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'totalAmtPaid',
										index: 'totalAmtPaid',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dmXchangeRate',
										index: 'dmXchangeRate',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dmTotalAmount',
										index: 'dmTotalAmount',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'euroTotalAmt',
										index: 'euroTotalAmt',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'salesDate',
										index: 'salesDate',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'salesPrice',
										index: 'salesPrice',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'salesCurrency',
										index: 'salesCurrency',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'dmXchangeRate2',
										index: 'dmXchangeRate2',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'bookId',
										index: 'bookId',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'pageRef1',
										index: 'pageRef1',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'lotNo',
										index: 'lotNo',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'catalogBy',
										index: 'catalogBy',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'catalogDate',
										index: 'catalogDate',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'watchRef1',
										index: 'watchRef1',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'watchRef2',
										index: 'watchRef2',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'watchRef3',
										index: 'watchRef3',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'updated',
										index: 'updated',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									},
									{
										name: 'pic',
										index: 'pic',
										width:80,
										align: 'left',
										sortable: true,
										editable: true,
										edittype: 'text',
										editrules: {edithidden:true},
										hidden: true
									}    
        					],
                viewrecords: true,
                rowNum : ${sessionScope.gridRowNum != null ? sessionScope.gridRowNum : 20 },
                width : 940,
                height: 'auto',
                rowList : [ 10, 20, 30, 50, 100, 200 ],
                pager : '#pagerGridContainer',
                viewrecords : true,
                caption : '<spring:message code="Watch.page.title" />',
                prmNames : {
                    search : "search",
                    order : "order",
                    oper : "action",
                    sort : "sort"
                },
                onPaging : function (pgButton) {
                    if (pgButton == "records") {
                        var newRowNum = $("#gridContainer").jqGrid('getGridParam', 'rowNum');
                        updatePreferedRowNum(newRowNum);
                    }
                    return pgButton;
                },
                loadComplete: function() {
                    var myGrid = jQuery("#gridContainer");
                    var ids = myGrid.jqGrid('getDataIDs');
                    
                	for (var i = 0; i < ids.length; i++) {
                	    var id=ids[i];
                        var watchId = myGrid.jqGrid('getCell', id, 'id');
                        var location = myGrid.jqGrid('getCell', id, 'location');
                        var maker = myGrid.jqGrid('getCell', id, 'maker');
                        var painter = myGrid.jqGrid('getCell', id, 'painter');
                        var caseNo = myGrid.jqGrid('getCell', id, 'caseNo');
                        var movementNo = myGrid.jqGrid('getCell', id, 'movementNo');
                        var picFullPath = myGrid.jqGrid('getCell', id, 'pic');
                        
                        // temp
                        //picFullPath = "http://www.istockphoto.com/file_thumbview_approve/1802740/2/istockphoto_1802740-gold-pocket-watch.jpg";

                        var contents='<table><tr><td valign="top" width="300">' +
                	    '<b>Watch ID: </b>' + myGrid.jqGrid('getCell',id,'id') + '<br/>' +
                	    '<b>Location: </b>' + myGrid.jqGrid('getCell',id,'location') + '<br/>' +
                	    '<b>Maker: </b>' + myGrid.jqGrid('getCell',id,'maker') + '<br/>' +
                	    '<b>Painter: </b>' + myGrid.jqGrid('getCell',id,'painter') + '<br/>' +
                	    '<b>Case No: </b>' + myGrid.jqGrid('getCell',id,'caseNo') + '<br/>' +
                	    '<b>Movement No: </b>' + myGrid.jqGrid('getCell',id,'movementNo') + '<br/>' +
                	    
                        '</td><td width="300"><img src="' + picFullPath + '" align="right" width="304" height="380"/></td></tr></table>';

                        var contents = $('<div id="imageTooltip">'  
                            + '<table border="0" cellspacing="0" cellpadding="0" align="center">'  
                            + '<tr>'
                            + '<td valign="top">'
	                            + '<table border="0" cellspacing="0" cellpadding="0" align="center">'  
	                            + '<tr>'
	                            + '   <td class="tooltipLabel" WIDTH=100><b><spring:message code="Watch.id" /></b></td>'
	                            + '   <td class="tooltipData" WIDTH=200>' + watchId + '</td>'
	                            + '</tr>'
	                            + '<tr>'
	                            + '   <td class="tooltipLabel" WIDTH=100><b><spring:message code="Watch.location" /></b></td>'
	                            + '   <td class="tooltipData" WIDTH=200>' + location + '</td>'
	                            + '</tr>'
	                            + '<tr>'
	                            + '   <td class="tooltipLabel" WIDTH=100><b><spring:message code="Watch.maker" /></b></td>'
	                            + '   <td class="tooltipData" WIDTH=200>' + maker + '</td>'
	                            + '</tr>'
	                            + '<tr>'
	                            + '   <td class="tooltipLabel" WIDTH=100><b><spring:message code="Watch.painter" /></b></td>'
	                            + '   <td class="tooltipData" WIDTH=200>' + painter + '</td>'
	                            + '</tr>'
	                            + '<tr>'
	                            + '   <td class="tooltipLabel" WIDTH=100><b><spring:message code="Watch.caseNo" /></b></td>'
	                            + '   <td class="tooltipData" WIDTH=200>' + caseNo + '</td>'
	                            + '</tr>'
	                            + '<tr>'
	                            + '   <td class="tooltipLabel" WIDTH=100><b><spring:message code="Watch.movementNo" /></b></td>'
	                            + '   <td class="tooltipData" WIDTH=200>' + movementNo + '</td>'
	                            + '</tr>'
	                            + '</table>'
                            + '</td>'
                            + '<td valign="top">'
	                            + '<table border="0" cellspacing="0" cellpadding="0" align="center">'  
	                            + '<tr>'
	                            + '   <td WIDTH=300><img src="' + picFullPath + '" align="right" WIDTH=300/></td>'
	                            + '</tr>'
	                            + '</table>'
                            + '</td>'
                            + '</tr>'
                            + '</table>'
                            + '</div>');
                        $("#" + id).qtip({
                            content: contents,
                            position: {
                            	adjust: { screen: true, resize: true },
                               corner: {
                                  tooltip: 'bottomMiddle',
                                  target: 'topMiddle'
                               }
                            },
                            style: {
                               tip: true, // Give it a speech bubble tip with automatic corner detection
                               name: 'light',
                               background: '#F5DCB2',
                               border: {
                                   width: 7,
                                   radius: 5,
                                   color: '#CB8B21'
                                },
                               width: 600
                            }
               			});
                	}   
                },
                emptyDataText: "<spring:message code='General.list.emptyrecords' />"
            }).jqGrid('filterToolbar', { searchOnEnter: true });

            function initPopup() {
                $("#editmodgridContainer").width(800); 
                $("#viewmodgridContainer").width(800); 
                $(".CaptionTD").width(265); 
                $("input.FormElement").width(495); 
            }

            function updatePreferedRowNum(newRowNum) {
                $.ajax({
                    type: "POST",
                    url: "${pageContext.request.contextPath}/watch/updatePreferedGridRowNum.action",
                    data: {
                        newRowNum: newRowNum
                    },
                    success: function(jsonString) {}
                });
            }

            var timeoutHnd;
            function doSearch(ev) {
                if(timeoutHnd) {
                    clearTimeout(timeoutHnd);
                }
                timeoutHnd = setTimeout(gridReload, 500);
            }

            function gridReload() {
                var grid = $("#gridContainer");
                grid[0].triggerToolbar();
            }

            jQuery("#gridContainer").jqGrid('navGrid',
                    '#pagerGridContainer', {
                        edit : true,
                        add : true,
                        view : true,
                        del : true,
                        search : false
                    },
                    // prmEdit, prmAdd, prmDel, prmSearch, prmView
                    {
                        closeAfterAdd: true,
                        closeAfterEdit: true,
                        viewPagerButtons: false,
                        modal: true,
                        width:500,
                        //top: 100,
                        //left: 100,
                        url:'management/update.action',
                        afterSubmit : DomainProcessor.processUpdateResponse,
                        ajaxEditOptions : {
                            type : 'POST',
                            contentType : 'application/json'
                        },
	                    serializeEditData: function(data) {
	                        return $.toJSON($.extend({}, data));
	                    },
                        beforeShowForm : function (formid) {
                        	initPopup();
                        }
                    },
                    {
                        closeAfterAdd: true,
                        closeAfterEdit: true,
                        viewPagerButtons: false,
                        modal: true,
                        width:500,
                        //top: 100,
                        //left: 100,
                        url:'management/insert.action',
                        afterSubmit : DomainProcessor.processInsertResponse,
                        ajaxEditOptions : {
                            type : 'POST',
                            contentType : 'application/json'
                        },
                        serializeEditData: function(data) {
                            return $.toJSON($.extend({}, data, {id:0}));
                        },
                        beforeShowForm : function (formid) {
                        	initPopup();
                        }
                    },
                    {
                        url:'management/delete.action'
                    },
                    {},
                    {
                    	viewPagerButtons: false,
                        beforeShowForm : function (formid) {
                        	initPopup();
                        }
                    }  // view
            );
        }
    };
}
    
</script>